package com.owg.jigsaw.hierarchy;

import java.util.LinkedHashSet;

/**A {@link TypeNode} representing a Java class. Since no more than one instance should exist for each class, the constructor is not exposed;
 * please refer to the appropriate {@link TypeHierarchy} to retrieve instances of this class.*/
public class CustomTypeNode extends TypeNodeBase implements ReparentableTypeNode
{
	private String name;
	private final LinkedHashSet<TypeNode> parents = new LinkedHashSet<>();
	
	CustomTypeNode(String name)
	{
		super();
		this.name = name;
	}
	
	@Override
	public Object getKey()
	{
		return name;
	}
	
	@Override
	public boolean isChildOf(TypeNode n)
	{
		return n != this && n != null && parents.contains(n);
	}

	@Override
	public void setIsParent(TypeNode n, boolean isParent)
	{
		if(isParent)
			parents.add(n);
		else
			parents.remove(n);
	}
}
